package drds.binlog.data_object;


import com.google.gson.annotations.SerializedName;
import drds.binlog.common.Authors;
import drds.common.Author;
import lombok.Getter;
import lombok.Setter;

/**
 * message row 每行变更数据的数据结构
 */
@Author(name = Authors.LI_YANG)
public final class RowChange extends DataObject
{
    /**
     * <pre>
     * * ddl/query的schemaName，会存在跨库ddl，需要保留执行ddl的当前schemaName  *
     * </pre>
     */
    @SerializedName("ddlSchemaName")
    @Setter
    @Getter
    public volatile String ddlSchemaName;

    //
    @SerializedName("tableId")
    @Setter
    @Getter
    public long tableId;


    //
    @SerializedName("eventTypeValue")
    @Setter
    @Getter
    public int eventTypeValue;
    //
    //
    @SerializedName("isDdl")
    @Setter
    @Getter
    public boolean isDdl;
    /**
     * <pre>
     * * ddl/query的sql语句  *
     * </pre>
     */
    @SerializedName("sql")
    @Setter
    @Getter
    public volatile String sql;
    /**
     * <pre>
     * * 一次数据库变更可能存在多行  *
     * </pre>
     */
    @SerializedName("rowDataList")
    @Setter
    @Getter
    public java.util.List<RowData> rowDataList = java.util.Collections.emptyList();
    //
    @SerializedName("propertyList")
    @Setter
    @Getter
    public java.util.List<KeyValuePair> propertyList = java.util.Collections.emptyList();
    //
    @SerializedName("eventType")
    @Setter
    @Getter
    private EventType eventType;


    public RowChange()
    {
        tableId = 0L;
        sql = "";
        ddlSchemaName = "";
    }


    public EventType getEventType()
    {
        EventType eventType = EventType.valueOf(eventTypeValue);
        return eventType == null ? EventType.unrecognized : eventType;
    }


}
